#include "StdAfx.h"
#include "HPBarTheme.h"
#include "StatusBarHPBarPane.h"

CHPBarTheme::CHPBarTheme(CXTPPaintManager* pPaintManager)
	: CXTPProgressPaintManager(pPaintManager)
{
}

CHPBarTheme::~CHPBarTheme()
{
}

void CHPBarTheme::DrawProgress(CDC* pDC, CXTPProgressBase* pProgressBase)
{
	CRect rc(pProgressBase->GetProgressRect());

	XTPPaintTheme theme = GetPaintManager()->BaseTheme();

	int nLower, nUpper, nPos;
	pProgressBase->GetRange(nLower, nUpper);
	nPos = pProgressBase->GetPos();

	int nWidth, dxBlock;

	CRect rcClient(rc);

	rcClient.DeflateRect(2, 2);

	nWidth = rcClient.right - rcClient.left;
	dxBlock = (rcClient.bottom - rcClient.top) * 2 / 3;

	int x = MulDiv(nWidth, nPos - nLower, nUpper - nLower);


	pDC->FillSolidRect(rc, GetXtremeColor(COLOR_BTNFACE));
	pDC->Draw3dRect(rc, GetXtremeColor(COLOR_3DSHADOW), GetXtremeColor(COLOR_3DSHADOW));

	if (rcClient.Width() < 2)
		return;

	CStatusBarHPBarPane* pProgressBar = dynamic_cast<CStatusBarHPBarPane*>(pProgressBase);

	pDC->FillSolidRect(rcClient.left, rcClient.top, x, rcClient.Height(), pProgressBar->GetBarColor());

	pDC->SetTextColor(pProgressBar->GetTextColor());
	pDC->SetBkMode(TRANSPARENT);	
	CXTPFontDC font(pDC, pProgressBar->GetTextFont());
	pDC->DrawText(pProgressBar->GetText(), rc, DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX | DT_VCENTER | DT_CENTER);
}